/**
 * @Author: 陈瑞鹏
 * @Date:   2022-11-02 09:51:23
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2025-01-07 14:21:44
 */

export const HttpConfig = {

  DOMAIN_NAME: "http://guard.game4.cn/",

  SOCKET_NAME: "ws://tuanjiangame.game4.cn/shuchaopiao",
  // SOCKET_NAME: "ws://test.tuanjian.game4.cn/shuchaopiao",

  HEADERS_TEXT: { "Content-Type": "application/x-www-form-urlencoded" },

  HEADERS_JSON: { "Content-Type": "application/json" }
}

export default class NetManager {

  private static _ins: NetManager = null;

  public static get ins(): NetManager {

    if (this._ins == null) {
      this._ins = new NetManager();
    }
    return this._ins;
  }

  /**
   * 获取地址栏参数
   */
  public getsearchUrl(): string {

    let searchUrl: string = "";

    let e = CC_DEBUG ? 1 : 2;
    // console.log("e:", e)
    if (e == 2) {
      searchUrl = window.location.search;
    } else if (e == 1) {
      let sanguoName = localStorage.getItem("sanguoName");

      // if (!sanguoName) {

      sanguoName = Math.floor(Math.random() * 10000).toString();

      localStorage.setItem("sanguoName", sanguoName);
      // }

      searchUrl = "?username=" + sanguoName + "&serverid=1&time=1571710275&closepay=2&showad=0&flag=8345addc4d2d8a16c62e24e81bc8a362&unid=&showbtn=0&qhchannel=qunhei_1571710275_7154417&qhchannelid=7154417&nname=%E3%80%82%E3%80%82%E3%80%82&uimg=https%3A%2F%2Fm.qunhei.com%2FStatic%2FDefault%2FHome%2Fimages%2Fbg_touxiang_wutouxiang.png&isadult=1";

    }

    return searchUrl;

  }

  /**
   * 获取参数
   * @param str 
   * @param key 
   */
  public getParam(key: string, str: string = ""): any {

    if (!str)
      str = this.getsearchUrl();

    let strArr: Array<any> = str.substring(1).split("&");

    for (let i: number = 0; i < strArr.length; i++) {

      let paramsArr: Array<any> = strArr[i].split("=");

      if (paramsArr[0] == key) {

        return paramsArr[1];
      }
    }
    return null;
  }
}